package iotwisp.school.authorization.entity;

import iotwisp.base.orm.StringIdBaseEntity;
import iotwisp.school.area.entity.Area;
import iotwisp.school.user.entity.User;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import javax.persistence.*;

/**
 * 设备授权
 */
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
@DynamicUpdate
@DynamicInsert
@Entity
@Table(name = M.TABLE_PREFIX + "area_authorization")
public class AreaAuthorization extends StringIdBaseEntity {

    /**
     * 授权的区域
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "area_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Area area;

    /**
     * 获得授权的用户
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private User user;
    
    /**
     * 是否可查看
     */
    @Type(type = "yes_no")
    @Column(name = "is_allow_check")
    private Boolean allowCheck;

    /**
     * 是否可操作
     */
    @Type(type = "yes_no")
    @Column(name = "is_allow_operate")
    private Boolean allowOperate;
}
